


$(document).ready(function () {




    $( window ).resize(function() {
        setTimeout(function() {


            $('.dataTables_scrollBody').height($(window).height()-155);

        }, 1);

    });
});

function dataTableObj()
{
   var obj=new Object();
   obj.CreatDataTable=function(id,bsort,e,bfilter)
    {
       
             if($.trim(e)==''||!ExpInteger.test(e)){
                if($('#'+id).find('tfoot').length>0){
                    temp = parseInt(htable) -$('#'+id).find('tfoot').length *24; 
                    e =  temp+'px';
                }else{
                   e = htable ; 
                }
                 
             }
             if(bsort!=true){
               bsort=false;  
             }
             if(bfilter!=true){
               bfilter=false;  
             }
              oTable = $('#'+id).dataTable( {
  //                     "sDom": 'T<"clear">lfrdtip',
                       "bAutoWidth":true,
                        "bFilter": bfilter,
                        "sScrollY": e,
                        "sScrollX": "100%",
                        "bJQueryUI": true,
                        "bSort": bsort,
                        "aLengthMenu": [[-1,20,50], ["Tất cả",20,50]],
                        "sPaginationType": "full_numbers"
                         });
                                
    }
    obj.CreatDataTableGroup=function(id,bsort,e,index)
    {                        index=0; 
       
             if($.trim(e)==''||!ExpInteger.test(e)){
                if($('#'+id).find('tfoot').length>0){
                    temp = parseInt(htable) -$('#'+id).find('tfoot').length *24; 
                    e =  temp+'px';
                }else{
                   e = htable ; 
                }
                 
             }
             if(bsort!=true){
               bsort=false;  
             }
             if(!ExpInteger.test(index)){
                 index=0;
             }        
        oTable = $('#'+id).dataTable( {
                        "fnDrawCallback": function ( oSettings ) {
                            if ( oSettings.aiDisplay.length == 0 )
                            {
                                return;
                            }
                             
                            var nTrs = $('#'+id +' tbody tr');
                            var iColspan = nTrs[0].getElementsByTagName('td').length;
                            var sLastGroup = "";
                            for ( var i=0 ; i<nTrs.length ; i++ )
                            {
                                var iDisplayIndex = oSettings._iDisplayStart + i;
                                var sGroup = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex] ]._aData[index];
                                if ( sGroup != sLastGroup )
                                {
                                    var nGroup = document.createElement( 'tr' );
                                    var nCell = document.createElement( 'td' );
                                    nCell.colSpan = iColspan;
                                    nCell.className = "group";
                                    nCell.innerHTML = sGroup;
                                    nGroup.appendChild( nCell );
                                    nTrs[i].parentNode.insertBefore( nGroup, nTrs[i] );
                                    sLastGroup = sGroup;
                                }
                            }
                        },
                        "aoColumnDefs": [
                            { "bVisible": false, "aTargets": [ index ] }
                        ],
                        "aaSortingFixed": [[ 0, 'asc' ]],
                        "aaSorting": [[ 1, 'asc' ]],
                        "sScrollY": e,
                        "sScrollX": "100%",
                        "bJQueryUI": true,
                        "bSort": bsort,
                        "aLengthMenu": [[-1,20,50], ["Tất cả",20,50]],
                        "sPaginationType": "full_numbers"
                         });
    }
    
//    obj.AddDataTable=function(arrParam)
//    {
//        oTable.fnAddData([ arrParam[0],
//                           arrParam[1]+ '<input type="hidden" id="hd_city_temp" value="0"/>',
//                           arrParam[2],arrParam[3],arrParam[4],arrParam[5], arrParam[6] ]);
//    }
    obj.AddScriptProcess=function()
    {
                    
    }
    
   return obj;
}
function fnGetSelected( oTableLocal )
{
    var aReturn = new Array();
    var aTrs = oTableLocal.fnGetNodes();
     
    for ( var i=0 ; i<aTrs.length ; i++ )
    {
        if ( $(aTrs[i]).hasClass('row_selected') )
        {
            aReturn.push( aTrs[i] );
        }
    }
    return aReturn;
}
function fnGetSelectedSingle( oTableLocal )
{
    var aReturn = new Array();
    var aTrs = oTableLocal.fnGetNodes();
     
    for ( var i=0 ; i<aTrs.length ; i++ )
    {
        if ( $(aTrs[i]).hasClass('row_selected_single') )
        {
            aReturn.push( aTrs[i] );
        }
    }
    return aReturn;
}


